<!--
 * @Description: 登录界面
 * @Author: chaizhou
 * @Date: 2023-02-22 15:25:13
 * @LastEditTime: 2023-03-02 14:38:56
-->
<template>
  <div class="loginFormWrap">
    <h2>诉讼信息管理系统</h2>
    <el-tabs v-model="tabCurrent" class="demo-tabs">
      <el-tab-pane label="密码登录" name="psd">
        <el-form ref="formLogin" :model="fields" :rules="rules" status-icon label-width="0" class="demo-ruleForm">
          <el-form-item prop="username">
            <el-input v-model="fields.username" placeholder="请输入您的手机号码" autocomplete="off" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input placeholder="请输入密码" v-model="fields.password" type="password" autocomplete="off" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">登录</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="验证码登录" name="code">
        <el-form :ref="ruleFormRef" status-icon label-width="0" class="demo-ruleForm">
          <el-form-item prop="pass">
            <el-input placeholder="请输入您的手机号码" autocomplete="off" />
          </el-form-item>
          <el-form-item prop="checkPass">
            <el-input placeholder="请输入验证码" type="password" autocomplete="off">
              <template #append>
                <CodeMaker />
              </template>
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary">登录</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <span
      class="hoverText"
      @click="
        () => {
          emits('mode', 'find')
        }
      "
      >忘记密码？</span
    >
  </div>
</template>

<script setup>
import { reactive, toRefs, ref, onMounted } from 'vue'
import CodeMaker from './CodeMaker'
import { useRouter } from 'vue-router'
import { login } from './service'
import { encrypt } from '@/utils/jsencrypt'
const emits = defineEmits(['mode'])
const router = useRouter()

const formLogin = ref(null)
// 模式
// const props = defineProps({
//   mode: "",
//   type: Object,
// });
// console.log(props.mode);
// const formCode = ref(null);
const fields = reactive({
  username: '',
  password: ''
})
const rules = reactive({
  phone: [
    {
      required: true,
      message: '请输入手机号码',
      trigger: 'blur'
    }
    // { min: 11, max: 11, message: "长度为11", trigger: "blur" },
  ],
  password: [
    {
      required: true,
      message: '请输入密码',
      trigger: 'change'
    }
  ]
})

// 密码登录or验证码登录
const { tabCurrent } = toRefs(
  reactive({
    tabCurrent: 'psd'
  })
)

onMounted(() => {
  console.log(formLogin)
})

// 登录
const onSubmit = async () => {
  router.push('/lawsuit/case')
  // await formLogin.value.validate(async (valid) => {
  //   console.log(valid, fields)
  //   const { username, password } = fields
  //   if (valid) {
  //     const res = await login({ username, password: encrypt(password) })
  //     console.log('submit!')
  //     if (res?.success) router.push('/lawsuit/case')
  //   } else {
  //     console.log('error submit!', fields)
  //   }
  // })
}
</script>

<style lang="less">
.loginFormWrap {
  .el-tabs__nav-wrap::after {
    display: none;
  }
  .el-tabs__nav-scroll {
    text-align: center;
  }
  .el-tabs__nav {
    float: inherit;
  }
  .el-button--primary {
    width: 100%;
    margin-top: 46px;
    height: 48px;
    background-color: #2865ff;
    border-radius: 2px;
    font-size: 16px;
  }
  .el-input__wrapper {
    height: 48px;
  }
  .el-form-item {
    margin-bottom: 32px;
  }
  .hoverText {
    position: absolute;
    bottom: 104px;
    left: 0;
    color: #2865ff;
  }

  h2 {
    font-size: 28px;
    color: #262626;
    font-weight: bold;
    text-align: center;
    line-height: 36px;
    margin-bottom: 32px;
  }
  width: 338px;
  min-height: 320px;
  position: relative;
}
</style>
